package com.chalk.vo;

import lombok.Data;

import java.util.List;

/**
 * 购物车对象
 */
@Data
public class Cart {
    private static final long serialVersionUID = 4481052868689976217L;

    // 购物车明细项信息（格式为： SkuID,数量,选中标记|SkuID,数量,选中标记|SkuID,数量,选中标记|....）
    private String cartItemInfo;
    // 购物车的卖家商品信息（购物车商品项按卖家分组）
    private List<CartSellerItem> cartSellerItems;
    // 购物车商品金额
    private Double itemAmount;
    // 运费
    private Double deliveryFee;
    // 税费总金额
    private Double taxFee;
    // 促销折扣额
    private Double promoDiscount;
    // 会员等级折扣额
    private Double levelDiscount;
    // 购物车总金额
    private Double totalAmount;
    // 购物车最近更新时间（yyyyMMddHHmmss)
    private String lastUpdateTime;
    // 买家id
    private String buyerId;
    //商品总件数
    private Integer itemNumber;
    //失效商品
    private List<CartItem> cartItemList;
    //购物车商品积分
    private Integer itemIntegral;

    /**
     * 判断购物车是否为空
     *
     * @return
     */
    public boolean isEmpty() {
        boolean res = true;
        if (this.cartSellerItems != null) {
            for (CartSellerItem cartSellerItem : this.cartSellerItems) {
                if (cartSellerItem.getCartItems() != null && !cartSellerItem.getCartItems().isEmpty()) {
                    res = false;
                    break;
                }
            }
        }
        return res;
    }

    /**
     * 取购物车中商品数量
     *
     * @return
     */
    public int getCartItemNum() {
        int n = 0;
        if (this.cartSellerItems != null) {
            for (CartSellerItem cartSellerItem : this.cartSellerItems) {
                if (cartSellerItem != null && cartSellerItem.getCartItems() != null) {
                    n += cartSellerItem.getCartItems().size();
                }
            }
        }
        return n;
    }
}
